package com.project.filter;

import com.project.bean.UserBean;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * 顾客过滤器
 */
public class CustomerFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        UserBean user = (UserBean)request.getSession().getAttribute("loginUser");

        if(user != null && user.getGrade().equals("顾客")){
            filterChain.doFilter(request,response);
        }else {
            response.sendRedirect("/html/login.html?info=nologin");
        }
    }
}
